from typing import Callable


class BaseGraphNode(Callable):

    def __init__(self, node_config: dict):
        self.node_id = node_config.get("id")
        self.inputs = node_config.get("inputs")
        self.outputs = node_config.get("outputs")

    @classmethod
    def input_params_assem(cls, state, input_config: dict):
        """
        组装input入参
        Args:
            state: 状态
            input_config: 入参配置

        Returns: 组装好的参数
        """
        node_params = state.get("node_params")

        input_params = {}
        for input_config_param in input_config:
            param_type = input_config_param.get("type")
            key = input_config_param.get("key")
            value = input_config_param.get("value")
            if param_type == 'ref':
                ref_params = value.split(".")

                last_value = node_params
                for k in ref_params:
                    last_value = last_value.get(k)

                if last_value:
                    input_params.setdefault(key, last_value)
            else:
                input_params.setdefault(key, value)
        return input_params
